import { IFeidaoAiWeappPage } from '@dfeidao/atom-wxapp/interfaces';
import nodejs from '@dfeidao/atom-wxapp/msg/nodejs';
import render from '@dfeidao/atom-wxapp/render/render';
import get_local from '@dfeidao/atom-wxapp/local/get';
import set_local from '@dfeidao/atom-wxapp/local/set';
import show_toast from '@dfeidao/atom-wxapp/api/interaction/show-toast';
import get_bind from '@dfeidao/atom-wxapp/form/get';
import show_loading from '@dfeidao/atom-wxapp/api/interaction/show-loading';
import hide_loading from '@dfeidao/atom-wxapp/api/interaction/hide-loading';


export default async function a005(fd: IFeidaoAiWeappPage) {
	let search = get_bind(fd, 'search') as string;
	const page_no = get_local<number>(fd, 'page_no');//12
	let service;
    /*
    *判断是否有查询条件 如果有把查询name的服务名赋给他
    *如果没有就把查询全部的服务名赋给他
    */
	if (search) {
		service = "app-pick_list-findByName-1";
	} else {
		search = '';
		service = "app-pick_list-find-1";
	}
	try {
		const data = await nodejs<any[]>(service, {
			filter: {
				product_up_status: "已上架"
			},
			name: search,
			desc: ['pick_time'],
			page_size: 2,
			page_no: page_no + 1//23
		});
		console.log(data, '------------------');
		if (data.length > 0) {
			const list_data = get_local(fd, 'list_data') as any[];
			render(fd, { data: list_data.concat(data) });
			set_local(fd, 'page_no', page_no + 1);//23
			set_local(fd, 'list_data', list_data.concat(data));
		} else {
			show_toast('没有更多数据了', 'none');
		}
	} catch (error) {
		show_loading('读取数据失败');
		hide_loading();
	}
	// todo
}
